<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="卫星型号" prop="satelliteModel">
        <el-input
          v-model="queryParams.satelliteModel"
          placeholder="请输入卫星型号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模块标识" prop="moduleId">
        <el-input
          v-model="queryParams.moduleId"
          placeholder="请输入模块标识"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模块名称" prop="moduleName">
        <el-input
          v-model="queryParams.moduleName"
          placeholder="请输入模块名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称" prop="deviceName">
        <el-input
          v-model="queryParams.deviceName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="数据类型" prop="dataType">
        <el-input
          v-model="queryParams.dataType"
          placeholder="请输入数据类型"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据类型描述" prop="dataTypeDesc">
        <el-input
          v-model="queryParams.dataTypeDesc"
          placeholder="请输入数据类型描述"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包序列计数器" prop="packetSequenceCounter">
        <el-input
          v-model="queryParams.packetSequenceCounter"
          placeholder="请输入包序列计数器"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="副导头标识" prop="auxiliaryGuideHeadMarking">
        <el-input
          v-model="queryParams.auxiliaryGuideHeadMarking"
          placeholder="请输入副导头标识"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指令名称" prop="instructionName">
        <el-input
          v-model="queryParams.instructionName"
          placeholder="请输入指令名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指令代号" prop="instructionCode">
        <el-input
          v-model="queryParams.instructionCode"
          placeholder="请输入指令代号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指令标识" prop="instructionId">
        <el-input
          v-model="queryParams.instructionId"
          placeholder="请输入指令标识"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="差错域" prop="errorDomain">
        <el-input
          v-model="queryParams.errorDomain"
          placeholder="请输入差错域"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数顺序" prop="parameterSequence">
        <el-input
          v-model="queryParams.parameterSequence"
          placeholder="请输入参数顺序"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数代号" prop="parameterCode">
        <el-input
          v-model="queryParams.parameterCode"
          placeholder="请输入参数代号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数名称" prop="parameterName">
        <el-input
          v-model="queryParams.parameterName"
          placeholder="请输入参数名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数长度" prop="parameterLength">
        <el-input
          v-model="queryParams.parameterLength"
          placeholder="请输入参数长度"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数类型" prop="parameterType">
        <el-input
          v-model="queryParams.parameterType"
          placeholder="请输入参数类型"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理方式" prop="processingMethod">
        <el-input
          v-model="queryParams.processingMethod"
          placeholder="请输入处理方式"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数定义" prop="parameterDefinition">
        <el-input
          v-model="queryParams.parameterDefinition"
          placeholder="请输入参数定义"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="默认值" prop="defaultValue">
        <el-input
          v-model="queryParams.defaultValue"
          placeholder="请输入默认值"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数说明" prop="parameterDescription">
        <el-input
          v-model="queryParams.parameterDescription"
          placeholder="请输入参数说明"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作列" prop="operationColumn">
        <el-input
          v-model="queryParams.operationColumn"
          placeholder="请输入操作列"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="creator">
        <el-input
          v-model="queryParams.creator"
          placeholder="请输入创建人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人ID" prop="creatorId">
        <el-input
          v-model="queryParams.creatorId"
          placeholder="请输入创建人ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人" prop="updater">
        <el-input
          v-model="queryParams.updater"
          placeholder="请输入更新人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人ID" prop="updaterId">
        <el-input
          v-model="queryParams.updaterId"
          placeholder="请输入更新人ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除" prop="isDeleted">
        <el-select v-model="queryParams.isDeleted" placeholder="请选择是否删除" clearable>
          <el-option
            v-for="dict in is_deleted"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item label="创建日期" style="width: 308px">
        <el-date-picker
          v-model="daterangeCreateDate"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="执行时间" style="width: 308px">
        <el-date-picker
          v-model="daterangeExecuteTime"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="获取时间" style="width: 308px">
        <el-date-picker
          v-model="daterangeFetchTime"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="执行方式" prop="executeMethod">
        <el-select v-model="queryParams.executeMethod" placeholder="请选择执行方式" clearable>
          <el-option
            v-for="dict in execute_method"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="执行状态" prop="executeStatus">
        <el-select v-model="queryParams.executeStatus" placeholder="请选择执行状态" clearable>
          <el-option
            v-for="dict in execute_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['kamenxians1:control:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kamenxians1:control:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kamenxians1:control:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport00"
          v-hasPermi="['kamenxians1:control:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="mini"
            @click="uploadDialogVisible = true"
        >导入文件</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="mini"
            @click="handleExportword"
        >导出word</el-button>
      </el-col>


      <el-col :span="1.5">
        <el-button type="warning" icon="Download" @click="handleImport" v-hasPermi="['kamenxians1:control:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" icon="Download" @click="handleExport('excel')" v-hasPermi="['kamenxians1:control:export']">导出Excel</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="Document" @click="handleExport('pdf')" v-hasPermi="['kamenxians1:control:export']">导出PDF</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" icon="Document" @click="handleExport('word')" v-hasPermi="['kamenxians1:control:export']">导出Word</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 导入文件对话框 -->
    <el-dialog
        :title="'导入文件'"
        v-model="uploadDialogVisible"
        width="400px"
    >
      <el-upload
          ref="uploadComponent"
          class="upload-demo"
          drag
          :multiple="true"
          accept=".xls,.xlsx"
          :before-upload="beforeUpload"
          :http-request="customUploadRequest"
          size="mini"
      >
        <el-row :span="24" style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
          <el-col :span="6">
            <el-icon style="margin-top: 25px" class="el-icon--upload"><UploadFilled /></el-icon>
          </el-col>
          <el-col :span="18">
            <div class="el-upload__text">
              将文件拖到此处或点击
            </div>
          </el-col>
        </el-row>
      </el-upload>
      <template #footer>  <!-- 替换slot="footer"为#footer -->
        <el-button @click="handleClose">关闭</el-button>
      </template>
    </el-dialog>

    <el-table v-loading="loading" :data="controlList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="卫星型号" align="center" prop="satelliteModel" />
      <el-table-column label="模块标识" align="center" prop="moduleId" />
      <el-table-column label="模块名称" align="center" prop="moduleName" />
<!--      <el-table-column label="设备名称" align="center" prop="deviceName" />-->
      <el-table-column label="数据类型" align="center" prop="dataType" />
      <el-table-column label="数据类型描述" align="center" prop="dataTypeDesc" />
<!--      <el-table-column label="包序列计数器" align="center" prop="packetSequenceCounter" />-->
<!--      <el-table-column label="副导头标识" align="center" prop="auxiliaryGuideHeadMarking" />-->
      <el-table-column label="指令名称" align="center" prop="instructionName" />
      <el-table-column label="指令代号" align="center" prop="instructionCode" />
      <el-table-column label="指令标识" align="center" prop="instructionId" />
      <el-table-column label="差错域" align="center" prop="errorDomain" />
      <el-table-column label="参数顺序" align="center" prop="parameterSequence" />
      <el-table-column label="参数代号" align="center" prop="parameterCode" />
      <el-table-column label="参数名称" align="center" prop="parameterName" />
      <el-table-column label="参数长度" align="center" prop="parameterLength" />
      <el-table-column label="参数类型" align="center" prop="parameterType" />
      <el-table-column label="处理方式" align="center" prop="processingMethod" />
      <el-table-column label="参数定义" align="center" prop="parameterDefinition" />
      <el-table-column label="默认值" align="center" prop="defaultValue" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="量纲" align="center" prop="dimension" />
      <el-table-column label="参数说明" align="center" prop="parameterDescription" />
      <el-table-column label="操作列" align="center" prop="operationColumn" />
      <el-table-column label="创建人" align="center" prop="creator" />
      <el-table-column label="创建人ID" align="center" prop="creatorId" />
      <el-table-column label="更新人" align="center" prop="updater" />
      <el-table-column label="更新人ID" align="center" prop="updaterId" />
      <el-table-column label="是否删除" align="center" prop="isDeleted">
        <template #default="scope">
          <dict-tag :options="is_deleted" :value="scope.row.isDeleted"/>
        </template>
      </el-table-column>
      <el-table-column label="创建日期" align="center" prop="createDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行时间" align="center" prop="executeTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.executeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="获取时间" align="center" prop="fetchTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.fetchTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行方式" align="center" prop="executeMethod">
        <template #default="scope">
          <dict-tag :options="execute_method" :value="scope.row.executeMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="执行状态" align="center" prop="executeStatus">
        <template #default="scope">
          <dict-tag :options="execute_status" :value="scope.row.executeStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['kamenxians1:control:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['kamenxians1:control:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 导入弹窗 -->
    <el-dialog :title="uploadKmx.title" v-model="uploadKmx.open" width="400px" append-to-body>
      <el-upload
          ref="uploadRef"
          :limit="1"
          accept=".xlsx,.xls"
          :action="uploadKmx.url + '?updateSupport=' + uploadKmx.updateSupport"
          :headers="uploadKmx.headers"
          :disabled="uploadKmx.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :on-error="handleFileError"
          :auto-upload="false"
          drag
      >
        <el-icon><UploadFilled /></el-icon>
        <div>将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
          <div>
            <el-checkbox v-model="uploadKmx.updateSupport" /> 是否更新已存在数据
            <el-link type="primary" :underline="false" @click="importTemplate">下载模板</el-link>
          </div>
        </template>
      </el-upload>
      <template #footer>
        <el-button type="primary" @click="submitFileForm">确定</el-button>
        <el-button @click="uploadKmx.open=false">取消</el-button>
      </template>
    </el-dialog>



    <!-- 添加或修改卫星遥控对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="controlRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="卫星型号" prop="satelliteModel">
          <el-input v-model="form.satelliteModel" placeholder="请输入卫星型号" />
        </el-form-item>
        <el-form-item label="模块标识" prop="moduleId">
          <el-input v-model="form.moduleId" placeholder="请输入模块标识" />
        </el-form-item>
        <el-form-item label="模块名称" prop="moduleName">
          <el-input v-model="form.moduleName" placeholder="请输入模块名称" />
        </el-form-item>
        <el-form-item label="数据类型描述" prop="dataTypeDesc">
          <el-input v-model="form.dataTypeDesc" placeholder="请输入数据类型描述" />
        </el-form-item>
        <el-form-item label="指令名称" prop="instructionName">
          <el-input v-model="form.instructionName" placeholder="请输入指令名称" />
        </el-form-item>
        <el-form-item label="指令代号" prop="instructionCode">
          <el-input v-model="form.instructionCode" placeholder="请输入指令代号" />
        </el-form-item>
        <el-form-item label="指令标识" prop="instructionId">
          <el-input v-model="form.instructionId" placeholder="请输入指令标识" />
        </el-form-item>
        <el-form-item label="差错域" prop="errorDomain">
          <el-input v-model="form.errorDomain" placeholder="请输入差错域" />
        </el-form-item>
        <el-form-item label="参数顺序" prop="parameterSequence">
          <el-input v-model="form.parameterSequence" placeholder="请输入参数顺序" />
        </el-form-item>
        <el-form-item label="参数代号" prop="parameterCode">
          <el-input v-model="form.parameterCode" placeholder="请输入参数代号" />
        </el-form-item>
        <el-form-item label="参数名称" prop="parameterName">
          <el-input v-model="form.parameterName" placeholder="请输入参数名称" />
        </el-form-item>
        <el-form-item label="参数长度" prop="parameterLength">
          <el-input v-model="form.parameterLength" placeholder="请输入参数长度" />
        </el-form-item>
        <el-form-item label="处理方式" prop="processingMethod">
          <el-input v-model="form.processingMethod" placeholder="请输入处理方式" />
        </el-form-item>
        <el-form-item label="参数定义" prop="parameterDefinition">
          <el-input v-model="form.parameterDefinition" placeholder="请输入参数定义" />
        </el-form-item>
        <el-form-item label="默认值" prop="defaultValue">
          <el-input v-model="form.defaultValue" placeholder="请输入默认值" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="量纲" prop="dimension">
          <el-input v-model="form.dimension" placeholder="请输入量纲" />
        </el-form-item>
        <el-form-item label="参数说明" prop="parameterDescription">
          <el-input v-model="form.parameterDescription" placeholder="请输入参数说明" />
        </el-form-item>
        <el-form-item label="操作列" prop="operationColumn">
          <el-input v-model="form.operationColumn" placeholder="请输入操作列" />
        </el-form-item>
        <el-form-item label="创建人" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建人ID" prop="creatorId">
          <el-input v-model="form.creatorId" placeholder="请输入创建人ID" />
        </el-form-item>
        <el-form-item label="更新人" prop="updater">
          <el-input v-model="form.updater" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新人ID" prop="updaterId">
          <el-input v-model="form.updaterId" placeholder="请输入更新人ID" />
        </el-form-item>
        <el-form-item label="是否删除" prop="isDeleted">
          <el-select v-model="form.isDeleted" placeholder="请选择是否删除">
            <el-option
              v-for="dict in is_deleted"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建日期" prop="createDate">
          <el-date-picker clearable
            v-model="form.createDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="执行时间" prop="executeTime">
          <el-date-picker clearable
            v-model="form.executeTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择执行时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="获取时间" prop="fetchTime">
          <el-date-picker clearable
            v-model="form.fetchTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择获取时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="执行方式" prop="executeMethod">
          <el-select v-model="form.executeMethod" placeholder="请选择执行方式">
            <el-option
              v-for="dict in execute_method"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="执行状态" prop="executeStatus">
          <el-select v-model="form.executeStatus" placeholder="请选择执行状态">
            <el-option
              v-for="dict in execute_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Control">
import { listControl, getControl, delControl, addControl, updateControl,upload } from "@/api/kamenxians1/control";
import {ElMessage} from "element-plus";
import {upfile} from "@/api/demo/us.js";

import {   importDataSp1stSatelliteRemoteControl, importTemplateSp1stSatelliteRemoteControl, exportExcelSp1stSatelliteRemoteControl, exportPdfSp1stSatelliteRemoteControl, exportWordSp1stSatelliteRemoteControl } from '@/api/kamenxians1/control'
import request from "@/utils/request.js";

import { getToken } from '@/utils/auth'
const { proxy } = getCurrentInstance();
const { is_deleted, execute_method, execute_status } = proxy.useDict('is_deleted', 'execute_method', 'execute_status');

const controlList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangeCreateTime = ref([]);
const daterangeUpdateTime = ref([]);
const daterangeCreateDate = ref([]);
const daterangeExecuteTime = ref([]);
const daterangeFetchTime = ref([]);


const uploadDialogVisible = ref(false);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    satelliteModel: null,
    moduleId: null,
    moduleName: null,
    deviceName: null,
    dataType: null,
    dataTypeDesc: null,
    packetSequenceCounter: null,
    auxiliaryGuideHeadMarking: null,
    instructionName: null,
    instructionCode: null,
    instructionId: null,
    errorDomain: null,
    parameterSequence: null,
    parameterCode: null,
    parameterName: null,
    parameterLength: null,
    parameterType: null,
    processingMethod: null,
    parameterDefinition: null,
    defaultValue: null,
    unit: null,
    dimension: null,
    parameterDescription: null,
    operationColumn: null,
    creator: null,
    creatorId: null,
    updater: null,
    updaterId: null,
    isDeleted: null,
    createDate: null,
    executeTime: null,
    fetchTime: null,
    executeMethod: null,
    executeStatus: null
  },
  rules: {
    creator: [
      { required: true, message: "创建人不能为空", trigger: "blur" }
    ],
    creatorId: [
      { required: true, message: "创建人ID不能为空", trigger: "blur" }
    ],
    updater: [
      { required: true, message: "更新人不能为空", trigger: "blur" }
    ],
    updaterId: [
      { required: true, message: "更新人ID不能为空", trigger: "blur" }
    ],
    createTime: [
      { required: true, message: "创建时间不能为空", trigger: "blur" }
    ],
    updateTime: [
      { required: true, message: "更新时间不能为空", trigger: "blur" }
    ],
    isDeleted: [
      { required: true, message: "是否删除不能为空", trigger: "change" }
    ],
    createDate: [
      { required: true, message: "创建日期不能为空", trigger: "blur" }
    ],
    executeMethod: [
      { required: true, message: "执行方式不能为空", trigger: "change" }
    ],
    executeStatus: [
      { required: true, message: "执行状态不能为空", trigger: "change" }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);


const beforeUpload = (file) => {
  const isLxls = file.name.endsWith('.xls') || file.name.endsWith('.xlsx');
  const isSizeValid = file.size / 1024 / 1024 < 10;  // 限制10MB
  if (!isLxls) {
    ElMessage.error('请上传后缀名为.xls或.xlsx的文件');
    return false;
  }
  if (!isSizeValid) {
    ElMessage.error(`文件大小超过10MB限制，当前为${(file.size / 1024 / 1024).toFixed(2)}MB`);
    return false;
  }
  return true;
};

const customUploadRequest = (option) => {
  const formData = new FormData();
  console.log("1111112")
  formData.append('file', option.file);
  upload(formData).then(response => {
    console.log( response);
    const files = response.data;
    if(files>0){
      uploadComponent.value.clearFiles();  // 清空显示
      getList();
      uploadDialogVisible.value = false;
    }
    // getUniqueData();  // 若有此方法需定义
  }).catch(error => {
    option.onError(error);
  });
};

const handleClose = () => {
  uploadDialogVisible.value = false
  console.log("1111111")
  uploadComponent.value.clearFiles();  // 清空显示
  console.log('设置后 uploadDialogVisible 值:', uploadDialogVisible.value)
}

/** 查询卫星遥控列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
/*  if (null != daterangeCreateTime && '' != daterangeCreateTime) {
    queryParams.value.params["beginCreateTime"] = daterangeCreateTime.value[0];
    queryParams.value.params["endCreateTime"] = daterangeCreateTime.value[1];
  }
  if (null != daterangeUpdateTime && '' != daterangeUpdateTime) {
    queryParams.value.params["beginUpdateTime"] = daterangeUpdateTime.value[0];
    queryParams.value.params["endUpdateTime"] = daterangeUpdateTime.value[1];
  }
  if (null != daterangeCreateDate && '' != daterangeCreateDate) {
    queryParams.value.params["beginCreateDate"] = daterangeCreateDate.value[0];
    queryParams.value.params["endCreateDate"] = daterangeCreateDate.value[1];
  }
  if (null != daterangeExecuteTime && '' != daterangeExecuteTime) {
    queryParams.value.params["beginExecuteTime"] = daterangeExecuteTime.value[0];
    queryParams.value.params["endExecuteTime"] = daterangeExecuteTime.value[1];
  }
  if (null != daterangeFetchTime && '' != daterangeFetchTime) {
    queryParams.value.params["beginFetchTime"] = daterangeFetchTime.value[0];
    queryParams.value.params["endFetchTime"] = daterangeFetchTime.value[1];
  }*/
  listControl(queryParams.value).then(response => {
    controlList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    satelliteModel: null,
    moduleId: null,
    moduleName: null,
    deviceName: null,
    dataType: null,
    dataTypeDesc: null,
    packetSequenceCounter: null,
    auxiliaryGuideHeadMarking: null,
    instructionName: null,
    instructionCode: null,
    instructionId: null,
    errorDomain: null,
    parameterSequence: null,
    parameterCode: null,
    parameterName: null,
    parameterLength: null,
    parameterType: null,
    processingMethod: null,
    parameterDefinition: null,
    defaultValue: null,
    unit: null,
    dimension: null,
    parameterDescription: null,
    operationColumn: null,
    creator: null,
    creatorId: null,
    updater: null,
    updaterId: null,
    createTime: null,
    updateTime: null,
    isDeleted: null,
    createDate: null,
    executeTime: null,
    fetchTime: null,
    executeMethod: null,
    executeStatus: null
  };
  proxy.resetForm("controlRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeCreateTime.value = [];
  daterangeUpdateTime.value = [];
  daterangeCreateDate.value = [];
  daterangeExecuteTime.value = [];
  daterangeFetchTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加卫星遥控";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getControl(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改卫星遥控";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["controlRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateControl(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addControl(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除卫星遥控编号为"' + _ids + '"的数据项？').then(function() {
    return delControl(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport00() {
  proxy.download('kamenxians1/control/export', {
    ...queryParams.value
  }, `control_${new Date().getTime()}.xlsx`)
}
function handleExportword() {
  proxy.download('kamenxians1/control/word', {
    ...queryParams.value
  }, `control_${new Date().getTime()}.docx`)
}


/** 导出按钮操作 */
function handleExport1() {
  proxy.download('kamenxians1/control/export', {
    ...queryParams.value
  }, `control_${new Date().getTime()}.xlsx`)
}


// export function exportWordSp1stSatelliteRemoteControl(data) {
//   return request({ url: '/kamenxians1/control/exportWord', method: 'post', data, responseType: 'blob' })
// }


const uploadKmx = reactive({
  open: false,
  title: '',
  isUploading: false,
  updateSupport: false,
  url: import.meta.env.VITE_APP_BASE_API + '/kamenxians1/control/importData',
  headers: { Authorization: 'Bearer ' + getToken() }
})

function handleImport() {
  uploadKmx.open = true
  uploadKmx.title = '卫星遥控导入'
  uploadKmx.updateSupport = false
}
function importTemplate() {
  importTemplateSp1stSatelliteRemoteControl().then(res => proxy.downloadBlob(res.data, '卫星遥控导入模板.xlsx'))
}
function handleFileUploadProgress() { upload.isUploading = true }
function handleFileSuccess(res) {
  upload.open = false
  proxy.$refs.uploadRef.clearFiles()
  upload.isUploading = false
  ElMessage.success(res.msg)
}
function handleFileError(err) {
  upload.isUploading = false
  ElMessage.error(err?.message || '导入失败')
}
function submitFileForm() {
  proxy.$refs.uploadRef.submit()
}
/* 统一导出方法 */
function handleExport(type) {
  const map = {
    // excel: () => proxy.downloadBlob(exportExcelSp1stSatelliteRemoteControl(queryParams), '卫星遥控.xlsx'),
    // excel: () => proxy.downloadBlob(exportExcelSp1stSatelliteRemoteControl(queryParams), '卫星遥控.xlsx'),
    excel: () => proxy.download('kamenxians1/control/export', {
      ...queryParams.value
    }, `control_${new Date().getTime()}.卫星遥控.xlsx`),
    // pdf: () => proxy.downloadBlob(exportPdfSp1stSatelliteRemoteControl(queryParams), '卫星遥控.pdf'),
    pdf: () => proxy.download('kamenxians1/control/exportPdf', {
      ...queryParams.value
    }, `control_${new Date().getTime()}.卫星遥控.pdf`),
    // word: () => proxy.download(exportWordSp1stSatelliteRemoteControl(queryParams), '卫星遥控.docx'),
    // word: () => proxy.download(exportWordSp1stSatelliteRemoteControl(queryParams), '卫星遥控.docx')
    word: () => proxy.download('kamenxians1/control/exportWord', {
      ...queryParams.value
    }, `control_${new Date().getTime()}.卫星遥控.docx`)
  }
  map[type]()
}


getList();
</script>
